// run: $exec < bfdiff.in
#include <iostream>
#include <algorithm>
#include <string>

struct ene
{
	std::string s;
	int index;
	int dir;
};

bool operator<(ene const & a, ene const & b)
{
	return a.s > b.s || (a.s == b.s && a.index < b.index) ||
		(a.s == b.s && a.index == b.index && a.dir < b.dir);
}

int n;
std::string s, ts;

int main()
{
	int T;
	std::cin >> T;
	while (T--) {
		std::cin >> n;
		std::cin >> ts;
		s = ts + ts;
		std::vector<ene> data;
		for (int i = 0; i < n; i++) {
			ene tmp;
			tmp.s = s.substr(i, n);
			tmp.index = i + 1;
			tmp.dir = 0;
			data.push_back(tmp);
		}

		std::reverse(ts.begin(), ts.end());
		s = ts + ts;
		for (int i = 0; i < n; i++) {
			ene tmp;
			tmp.s = s.substr(i, n);
			tmp.index = n - i;
			tmp.dir = 1;
			data.push_back(tmp);
		}

		std::sort(data.begin(), data.end());
		std::cout << data[0].index << ' ' << data[0].dir << '\n';
	}
}

